class Solution {
    public:
        int totalFruit(vector<int>& fruits) {
            int n = fruits.size();
            int left  = 0;
            unordered_map<int,int> hash;
            int len = 0;
            for(int right = 0; right < n; right++)
            {
                // 进窗口
                hash[fruits[right]]++;
    
                while(hash.size() > 2)
                {
                    // 出窗口
                    hash[fruits[left]]--;
                    if(hash[fruits[left]] == 0)
                        hash.erase(fruits[left]);
                    left++;
                }
                len = max(right - left + 1,len);
                cout << len << " ";
            }
            return len;
        }
    };